//
//  UIView+PopAnimation.m
//  Unity-iPhone
//
//  Created by Karl on 2017/4/12.
//
//

#import "UIView+PopAnimation.h"

@implementation UIView (PopAnimation)

- (void)popAnimationShow:(BOOL)show{
    
    [self performSelector:@selector(pop) withObject:nil afterDelay:1.0];
    

}
- (void)pop{
    self.hidden = NO;
    self.transform = CGAffineTransformMakeScale(0, 0);
    
    [UIView animateKeyframesWithDuration:0.7 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeCubic animations:^{
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.4 animations:^{
            self.transform = CGAffineTransformMakeScale(1.2, 1.2);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.4 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(0.9, 0.9);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.6 relativeDuration:0.1 animations:^{
            self.transform = CGAffineTransformMakeScale(1.0, 1.0);
        }];
        
    } completion:^(BOOL finished) {
        if (finished) {
            NSLog(@"pop finished");
        }else{
            NSLog(@"pop not finished");
        }
    }];
}

- (void)buttonPop{

    self.transform = CGAffineTransformMakeScale(1.0, 1.0);

    [UIView animateKeyframesWithDuration:1.6 delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeCubic animations:^{
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.1 animations:^{
            self.transform = CGAffineTransformMakeScale(1.1, 1.1);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.1 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(0.9, 0.9);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.3 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(1.1, 1.1);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(0.9, 0.9);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.7 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(1.1, 1.1);
        }];
        [UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(0.9, 0.9);
        }];
        [UIView addKeyframeWithRelativeStartTime:1.1 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(1.1, 1.1);
        }];
        [UIView addKeyframeWithRelativeStartTime:1.3 relativeDuration:0.2 animations:^{
            self.transform = CGAffineTransformMakeScale(0.9, 0.9);
        }];
        [UIView addKeyframeWithRelativeStartTime:1.5 relativeDuration:0.1 animations:^{
            self.transform = CGAffineTransformMakeScale(1.0, 1.0);
        }];
        
    } completion:^(BOOL finished) {
        if (finished) {
            NSLog(@"btnpop finished");
        }else{
            NSLog(@"btnpop not finished");
        }
    }];

}

@end
